<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class createCategory extends Request {

	/**
	 * Determine if the user is authorized to make this request.
	 * @return bool
	 */
	public function authorize() {
		return true;
	}

	/**
	 * Get the validation rules that apply to the request.
	 * @return array
	 */
	public function rules() {
		return [
			'title'     => ['required', 'unique:categories,title'],
			'name'      => ['required', 'regex:/^[a-z_]{1,20}$/', 'unique:categories,name'],
			'parent_id' => ['exists:categories,parent_id'],
		];
	}

	/**
	 * 自定义验证信息
	 * @return array
	 */
	public function messages() {
		return [
			'title.type'    => '请填写分类名称',
			'title.unique'  => '分类名称已存在',
			'name.required' => '请填写分类编码',
			'name.regex'    => '分类编码必须为1-20位小写字母或下划线',
			'name.unique'   => '分类编码已存在',
		];
	}
}
